﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SMS_Server
{
    class Action_StaticResponse : Incoming_Action
    {
        public string ActionName;
        public string ActionFormat;
        public string ResponseString;
        public string[] ParamNames = null;

        public bool GetResult(string PhoneNumber, object[] Params, out string result)
        {
            if (ActionFormat == "")
                result = ResponseString;
            else
            {

                if (ParamNames == null)
                {
                    ActionFormat = ActionFormat.Replace("[", "").Replace("]", "");
                    ParamNames = ActionFormat.Split(' ');
                }
                if (Params.Length != ParamNames.Length)
                {
                    string resp = "Please write in the given format" + Encoding.ASCII.GetString(new byte[] { 13, 10 }) + ActionName.ToUpper();
                    for (int i = 0; i < ParamNames.Length; i++)
                    {
                        resp += " ";
                        resp += "[" + ParamNames[i] + "]";
                    }
                    result = resp; return true;
                }
                result = ResponseString;
                for (int i = 0; i < ParamNames.Length; i++)
                {
                    result = result.Replace("[" + ParamNames[i] + "]", Params[i].ToString());
                }
            }
            return true;
        }
    }
}
